<?php
require_once('../../../../conf/config.php.inc');
require_once(SYBMAS_LIB_PATH.'/liblogin.php.inc');
require_once(SYBMAS_LAYOUT_PATH.'/layout.php.inc');
require_once(SYBMAS_LIB_PATH.'/libsybmas.php.inc');
require_once(SYBMAS_LAYOUT_PATH.'/menu.php.inc');
verificar_inicio_sesion();

foreach($_POST as $key => $value){
	$$key=$value;
}

$time=time();
$ftime=date('H:i:s',$time);
$fdate=date('j/m/Y',$time);

$nombre_archivo="{$tablename}_{$time}.xls";

header('Content-type: application/vnd.ms-excel');
header("Content-Disposition: attachment; filename=$nombre_archivo");
header("Pragma: no-cache");
header("Expires: 0");

$sybuser_connection=start_default_sybuser_connection();
$query_columns="SELECT name ".		
		"FROM $dbname..syscolumns ".
		"WHERE id=$id ";

$result_columns=sybase_query($query_columns,$sybuser_connection);
$columns=array();
while($data=sybase_fetch_row($result_columns)){
	$columns[]=$data[0];
}
sybase_free_result($result_columns);


$query="SELECT * FROM ".
	"$dbname.$tableowner.$tablename ";


$sybuser_connection=start_default_sybuser_connection();
$result=sybase_query($query,$sybuser_connection);	
echo '<table width="80%" border="1">';
echo "<tr>\n";
foreach($columns as $column){
	echo "<th>".$column."</th>\n";
}
echo "</tr>\n";


if($result){
while($data=sybase_fetch_assoc($result)){
	echo "<tr>\n";
	foreach($columns as $columname){
		echo "<td>$data[$columname]&nbsp;</td>\n";
	}
	echo "</tr>\n";
}//$data=sybase_fetch_array($result)

sybase_free_result($result);
}//

echo "</table>";
	
//Cerrando conexiones a la base de datos
sybase_close($sybuser_connection);
?>